//
//  NRWUserProtocolView.m
//  NRWMall
//
//  Created by 邢毅 on 2018/6/22.
//  Copyright © 2018年 com.anpxd. All rights reserved.
//

#import "NRWUserProtocolView.h"
#import <WebKit/WebKit.h>
#import "NRWNavigationView.h"

@interface NRWUserProtocolView()<NRWNavigationViewDelegate>

@end

@implementation NRWUserProtocolView
{
    WKWebView *webView;
    NRWNavigationView *nav;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        nav = [[NRWNavigationView alloc] init];
        [nav setLeftTitle:nil image:@"nav_back"];
        nav.delegate = self;
        [self addSubview:nav];
        
        webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, getNavHeight(), SCREEN_WIDTH(), SCREEN_HEIGHT() - getNavHeight())];
        webView.backgroundColor = [UIColor whiteColor];
        [self addSubview:webView];
        
        self.backgroundColor = [UIColor whiteColor];
        
    }
    return self;
}

- (void)setUrl:(NSString *)url {
    
    _url = url;
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
}

- (void)setTitle:(NSString *)title {
    
    _title = title;
    
    nav.title = title;
}

- (void)show {
    
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    [[UIApplication sharedApplication].keyWindow bringSubviewToFront:self];
    self.frame = CGRectMake(SCREEN_WIDTH(), 0, SCREEN_WIDTH(), SCREEN_HEIGHT());
    
    [UIView animateWithDuration:0.25 animations:^{
       
        self.frame = CGRectMake(0, 0, SCREEN_WIDTH(), SCREEN_HEIGHT());
    } completion:^(BOOL finished) {
        
    }];
}

- (void)navigationViewLeftItemDidClick {
    
    [UIView animateWithDuration:0.25 animations:^{
       
        self.frame = CGRectMake(SCREEN_WIDTH(), 0, SCREEN_WIDTH(), SCREEN_HEIGHT());
    } completion:^(BOOL finished) {
        
        [self removeFromSuperview];
    }];
}

- (void)navigationViewRightItemDidClick {}

- (void)dealloc {
    
    NSLog(@"%@ dealloc", self.class);
}

@end
